<template>
    <div class="mainDiv">
        <div class="rowHead">
            <el-button type="success" icon="plus" @click="addvipgrade" v-qx="permission.add" v-show="noadd">会员等级</el-button>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="vipgrade" label="会员等级"></el-table-column>
            <el-table-column prop="vipname" label="会员名称"></el-table-column>
            <el-table-column prop="goodsdiscount" label="产品折扣">
                <template slot-scope="scope">{{zhekou(scope.row.goodsdiscount)+'%'}}</template>
            </el-table-column>
            <el-table-column prop="subjectdiscount" label="项目折扣">
                <template slot-scope="scope">{{zhekou(scope.row.subjectdiscount)+'%'}}</template>
            </el-table-column>
            <el-table-column prop="remarks" label="等级描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="addtime" label="添加日期">
                <template slot-scope="scope">{{time(scope.row.addtime)}}</template>
            </el-table-column>
            <el-table-column label="操作等级">
                <template slot-scope="scope">
                    <el-tooltip content="编辑等级" placement="left" :open-delay="800" v-if="scope.row.id!=1">
                        <el-button type="primary" icon="h-edit" size="small" @click="editVip(scope.row)" v-qx="permission.set">编辑等级</el-button>
                    </el-tooltip>
                    <i class="el-icon-h-level" v-else>&nbsp;默认等级</i>
                </template>
            </el-table-column>
        </el-table>
    </div>
</template>
<script>
import C from '@/common/common.js'
export default {
  name: 'vipgradeList',
  data () {
    return {
      list: [], // 会员等级列表
      noadd: false,
      permission: {
        add: 'shopvip_add',
        set: 'shopvip_set'
      }
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    addvipgrade: async function () {
      let res = await C.openBrowserWindow('/addVipgrade', {}, {
        transparent: true,
        frame: false,
        width: 400,
        height: 420,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.getList()
      }
    },
    time: function (unix) {
      let tm = new Date(unix * 1000)
      let yy = tm.getFullYear()
      let mm = tm.getMonth() + 1
      let dd = tm.getDate()
      return yy + '-' + mm + '-' + dd
    },
    zhekou: function (zk) {
      return parseFloat(zk * 100).toFixed(2)
    },
    sizeChange: function (val) {
      this.page.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.getList()
    },
    editVip: async function (row) {
      let res = await C.openBrowserWindow('/addVipgrade', { row: row }, {
        transparent: true,
        frame: false,
        width: 400,
        height: 420,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.getList()
      }
    },
    getList: async function () {
      let data = await C.ajax('/organization/vipgrade/vipgradelist', this.page, 'post')
      if (data) {
        this.list = data
        if (data.length > 5) {
          this.noadd = false
        } else {
          this.noadd = true
        }
      }
    }
  }
}
</script>